Dynomotion

Group: DynoMotion Message: 13647 From: dbt3000files Date: 7/26/2016
Subject: windows command line within c code
Sorry if this has been covered before.
I am trying to execute a command line from the c code.  Our machines running mach3 use vbscript, and you simply use the shell() command to execute an external command.  Is there a way to do something similar with kmotion?  I tried using the system() command, but it did not recognize it.


Here are some more details of what we use for our mach3 based machines:


shell ("netsh interface set interface""wireless network connection""enable")     'enables the wifi


shell ("python c:\stopmessage.py")    'runs a python script to notify operator of machine status


Thanks for any help anyone might have!

David

Group: DynoMotion Message: 13650 From: TKSOFT Date: 7/27/2016
Subject: Re: windows command line within c code
Hi David,

There isn't a PC shell command from within KFLOP User C Programs.

A workaround might be to create a (possibly hidden) User Button and
configure the Action to run a PC Program. You can then "Push" the User
Button from KFLOP using command:

#define PC_COMM_USER_BUTTON 13 // Persist+1 is which User Button to push

You can display a message box from KFLOP. See the command

// MessageBox Persist+1 = gather buffer offset (32-bit words) to message
string
// Persist+2 = Message Box Options (Icons and Buttons)
// Persist+3 = MessageBox Result returned
#define PC_COMM_MSG 15 // MessageBox
Persist+1=string,+2=Options,+3=result

and example: MessageBoxNoWait.c

HTH
Regards
TK



2016-07-26 10:58, dbt3000files@... [DynoMotion] wrote:
> Sorry if this has been covered before.
> I am trying to execute a command line from the c code. Our machines
> running mach3 use vbscript, and you simply use the shell() command to
> execute an external command. Is there a way to do something similar
> with kmotion? I tried using the system() command, but it did not
> recognize it.
>
> Here are some more details of what we use for our mach3 based
> machines:
>
> shell ("netsh interface set interface""wireless network
> connection""enable") 'enables the wifi
>
> shell ("python c:\stopmessage.py") 'runs a python script to notify
> operator of machine status
>
> Thanks for any help anyone might have!
>
> David
>
Group: DynoMotion Message: 13652 From: dbt3000files Date: 7/28/2016
Subject: Re: windows command line within c code
That should work.  Thanks!!
Group: DynoMotion Message: 13655 From: dbt3000files Date: 7/30/2016
Subject: Re: windows command line within c code
Thanks for all the help so far.
I have the c program working that will trigger a user button.  This user button runs an external .exe program that sends me a text message.  Everything works fine as long as the machine is at the end of its cycle and notifying me that it has finished, however when it tries to notify me before the end of the cycle I have problems.

The way I have traditionally stopped the machine in the event of a problem (loss of vacuum from the vacuum table etc.) is by running the DisableAxis( ) command.

example:

 if(ReadBit(input) == 0)
                {
                printf("check 7 failed\n");
                DisableAxis(0);
                DisableAxis(1);
                DisableAxis(2);
                DisableAxis(3);
                DisableAxis(4);
                spindle_off();
                success=0;

The G code continues to try and run at this point prompting the g code error window.  This was never a problem, but now it seems to be preventing any external program from running.

I had the idea to run a command to stop the g code, but I am not sure what command is appropriate.  I tried the StopImmediate command, but I think I am using it wrong.  Here's what I tried, but the command was not recognized.

 if(ReadBit(input) == 0)
                {
                printf("check 7 failed\n");
                StopImmediate(0);
                DisableAxis(0);
                DisableAxis(1);
                DisableAxis(2);
                DisableAxis(3);
                DisableAxis(4);
                spindle_off();
                success=0;

Also tried running the c code as Exc/Wait, but the external program doesn't get called when I set it up that way.

Any suggestions?
Thanks,
David
Group: DynoMotion Message: 13656 From: TKSOFT Date: 7/31/2016
Subject: Re: windows command line within c code
Hi David,

Unfortunately the GUI Thread (Windows Timer Loop) processes the commands
from KFLOP on the PC. Anything that throws up an error message will
block further commands until the message is cleared.

You might sent the Text Message before disabling the Axes which throws
up the error box.

Or do something like a Halt without throwing up an Error Box. See the
attached Program for how to do this.

Regards
TK


On 2016-07-30 15:04, dbt3000files@... [DynoMotion] wrote:
> Thanks for all the help so far.
> I have the c program working that will trigger a user button. This
> user button runs an external .exe program that sends me a text
> message. Everything works fine as long as the machine is at the end
> of its cycle and notifying me that it has finished, however when it
> tries to notify me before the end of the cycle I have problems.
>
> The way I have traditionally stopped the machine in the event of a
> problem (loss of vacuum from the vacuum table etc.) is by running the
> DisableAxis( ) command.
>
> example:
>
> if(ReadBit(input) == 0)
> {
> printf("check 7 failed\n");
> DisableAxis(0);
> DisableAxis(1);
> DisableAxis(2);
> DisableAxis(3);
> DisableAxis(4);
> spindle_off();
> success=0;
>
> The G code continues to try and run at this point prompting the g code
> error window. This was never a problem, but now it seems to be
> preventing any external program from running.
>
> I had the idea to run a command to stop the g code, but I am not sure
> what command is appropriate. I tried the StopImmediate command, but I
> think I am using it wrong. Here's what I tried, but the command was
> not recognized.
>
> if(ReadBit(input) == 0)
> {
> printf("check 7 failed\n");
> StopImmediate(0);
> DisableAxis(0);
> DisableAxis(1);
> DisableAxis(2);
> DisableAxis(3);
> DisableAxis(4);
> spindle_off();
> success=0;
>
> Also tried running the c code as Exc/Wait, but the external program
> doesn't get called when I set it up that way.
>
> Any suggestions?
> Thanks,
> David
  @@attachment@@
Group: DynoMotion Message: 13665 From: dbt3000files Date: 8/2/2016
Subject: Re: windows command line within c code
Tom, thank you so much for all your help! 

Everything is working beautifully.  I just wanted to run one more thing by you or anyone else who might have an opinion.  As far as best practices go, is there any reason not to stop a machine using the PC_COMM_HALT command instead of disabling the axes?  Right now we are using the PC_COMM_HALT when an problem is detected, and it seems to be a perfectly good solution. 

Thanks again!
David
Group: DynoMotion Message: 13667 From: TKSOFT Date: 8/3/2016
Subject: Re: windows command line within c code
Hi David,

Its up to you to determine what is necessary and works best for you.

Disabling the Axes should bring the axes to an abrupt but somewhat
uncontrolled stop without involving the the PC.

PC_COMM_HALT will instruct the PC to issue a hardware Feedhold bringing
the axes to a controlled stop and then rewind the GCode Interpreter to a
resume-able state from that point.

Regards
TK


On 2016-08-02 11:14, dbt3000files@... [DynoMotion] wrote:
> Tom, thank you so much for all your help!
>
> Everything is working beautifully. I just wanted to run one more
> thing by you or anyone else who might have an opinion. As far as best
> practices go, is there any reason not to stop a machine using the
> PC_COMM_HALT command instead of disabling the axes? Right now we are
> using the PC_COMM_HALT when an problem is detected, and it seems to be
> a perfectly good solution.
>
> Thanks again!
> David